//
//  UIBarButtonItem+Extensions.swift
//  Weibo
//
//  Created by User on 2017/3/14.
//  Copyright © 2017年 ZFY. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    /// 创建 UIBarButtonItem
    ///
    /// - Parameters:
    ///   - title: 按钮文字
    ///   - fontSize: 按钮文字大小
    ///   - normalColor: 按钮默认状态的颜色
    ///   - highlightedColor: 按钮选中状态的颜色
    ///   - target: target
    ///   - action: 按钮的点击事件
    convenience init(title: String, fontSize: CGFloat = 16, normalColor: UIColor, highlightedColor: UIColor, target: Any?, action: Selector, isBack: Bool = false) {
        
        let button : UIButton = UIButton.cz_textButton(title, fontSize: fontSize, normalColor: normalColor, highlightedColor: highlightedColor)
        button.addTarget(target, action: action, for: .touchUpInside)
        
        if isBack {
            let imageName = "navigationbar_back_withtext"
            
            button.setImage(UIImage(named: imageName), for: UIControlState(rawValue: 0))
            button.setImage(UIImage(named: imageName + "_highlighted"), for: .highlighted)
            
            button.sizeToFit()
        }
        
        // 用self.init 实例化 UIBarButtonItem
        self.init(customView: button)
    }
}

